#include "InputHandler.h"
#include "Player.h"
#include <SDL.h>


Player::Player(const Loader* pParams)
	: SDLGameObject(pParams) {} 


void Player::Render() const 
{
	SDLGameObject::Render();  
}


void Player::Update() 
{
	m_currentFrame = static_cast <int> ((SDL_GetTicks() / 100) % 6);

	handleInput(); 

	SDLGameObject::Update(); 
}


void Player::CleanUp()
{
}


void Player::handleInput()
{
	if (InputHandler::Instance() -> areJoyInit())
	{
		if (InputHandler::Instance() -> xAxis(0, 1) > 0 ||	
			    InputHandler::Instance() -> xAxis(0, 1) < 0)
		{
			m_velocity.x = 1 * InputHandler::Instance() -> xAxis(0, 1); 
		}

		if (InputHandler::Instance() -> yAxis(0, 1) > 0 || 
			    InputHandler::Instance() -> yAxis(0, 1) < 0)
		{
			m_velocity.y = 2 * InputHandler::Instance() -> yAxis(0, 1); 
		}

		if (InputHandler::Instance() -> xAxis(0, 2) > 0 || 
			    InputHandler::Instance() -> xAxis(0, 2) < 0)
		{
			m_velocity.x = 2 * InputHandler::Instance() -> xAxis(0, 2); 
		}

		if (InputHandler::Instance() -> yAxis(0, 2) > 0 || 
			    InputHandler::Instance() -> yAxis(0, 2) < 0)
		{
			m_velocity.y = 2 * InputHandler::Instance() -> yAxis(0, 2); 
		}

		if (InputHandler::Instance() -> joyButtonState(0, 3))
			m_velocity.x = 2; 
		/*
		// Sprite follows the mouse on click behaviour
		if (InputHandler::Instance() -> mouseButtonState(LEFT))
		{
			Vector2D temp(InputHandler::Instance() -> m_mousePosition);
			m_velocity = (temp - m_position) / 50;
		}

		// Use the arrow keys to navigate
		if (InputHandler::Instance() -> isKeyDown(SDL_SCANCODE_RIGHT))
			m_velocity.x = 2; 

		if (InputHandler::Instance() -> isKeyDown(SDL_SCANCODE_LEFT))
			m_velocity.x = -2; 

		if (InputHandler::Instance() -> isKeyDown(SDL_SCANCODE_UP))
			m_velocity.y = -2; 

		if (InputHandler::Instance() -> isKeyDown(SDL_SCANCODE_DOWN))
			m_velocity.y = 2; 
	*/
	}
}